<%@ page import="cleanstarxchange.server.*"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.text.DecimalFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<%
	Integer uid = Integer.parseInt(request.getParameter( "uid" ));
	Integer viewid = Integer.parseInt(request.getParameter( "viewid" ));
	DecimalFormat twoDForm = new DecimalFormat("#.##");
	DataStore ds = new DataStore();
	User user = ds.getUser( new Long(viewid) );
	double balance = user.getBalance();
	double assetValue = user.getAssetValue();
	balance = Double.valueOf((twoDForm.format(balance)));
	assetValue = Double.valueOf((twoDForm.format(assetValue)));
	ArrayList<OwnedStock> owned = ds.getOwnedStocks( new Long(viewid) );
%>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>StarXChange</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
<!--[if IE]>
<style type="text/css"> 
/* place css fixes for all versions of IE in this conditional comment */
.twoColElsLtHdr #sidebar1 { padding-top: 30px; }
.twoColElsLtHdr #mainContent { zoom: 1; padding-top: 15px; }
/* the above proprietary zoom property gives IE the hasLayout it needs to avoid several bugs */
</style>
<![endif]--></head>

<body class="twoColElsLtHdr">

<div id="container">
  <div id="header"><a href="index.jsp?uid=<%=uid%>"><img src="media/logo.jpg"/></a><!-- end #header --></div>
  <div id="sidebar1">
   <ul class="sidenav">
				<li>
                	<a href="portfolio.jsp?uid=<%=uid%>" title="My Portfolio">My Portfolio
                    <span>See how rich I am</span>
                    </a>
                    
                </li>
			    <li>
                	<a href="stocklist.jsp?uid=<%=uid%>" title="Stocks">Stocks
                    <span>See the market flow</span>
                    </a>
                </li>
				<li>
                	<a href="rank.jsp?uid=<%=uid%>" title="Rank">Rank
                    <span>Who is the winner now</span>
                    </a>
                </li>
				<li>
                	<a href="howtoplay.jsp?uid=<%=uid%>" title="HowToPlay">How To Play
                    <span>Learn how to play the game</span>
                    </a>
                </li>
			</ul>
    
  <!-- end #sidebar1 --></div>
  <div id="mainContent">
    <div id="uinf">
    			<br><%=user.getFirstName() %> <%=user.getLastName() %></br>
    			<br><%=user.getFirstName() %>'s Balance: $<%=balance %></br>
    			<br>Total Value of <%=user.getFirstName() %>'s Assets: $<%=assetValue %></br>
    			<div id="shortcut">
    			<table width="95%" border="0" cellspacing="2" cellpadding="2">
  					<tr>
    					<th scope="col">Celebrity Name</th>
    					<th scope="col">Purchase Price</th>
    					<th scope="col"># of Shares</th>
    					<th scope="col">Current Price</th>
    					<th scope="col">Market Value</th>
    					<th scope="col">Gain</th>
  					</tr>
  					<% for( int i=0; i<owned.size(); i++ ){ %>
  					<tr>
  					<%      
  							String color;
  							Long sid = owned.get(i).getID();
  							Stock stock = ds.getStock(sid);
  							OwnedStock ownedStock = owned.get(i);
  							double price = stock.getCurrentPrice();
  							double purchasePrice = owned.get(i).getPurchasePrice();
  							double mktVal = stock.getCurrentPrice()*owned.get(i).getQuantity();
  							double bghtVal = owned.get(i).getPurchasePrice() * owned.get(i).getQuantity();
  							double gain = ((mktVal - bghtVal)/bghtVal)*100;
  							gain = Double.valueOf(twoDForm.format(gain));
  							mktVal = Double.valueOf(twoDForm.format(mktVal));
  							bghtVal = Double.valueOf(twoDForm.format(bghtVal));
  							price = Double.valueOf(twoDForm.format(price));
  							purchasePrice = Double.valueOf(twoDForm.format(purchasePrice));
  							if( gain > 0 ) color = "#00ff00";
    						else if( gain < 0 ) color = "#ff0000";
    						else color = "#000000";
    				%>
    			
    					<td><a href="stockprofile.jsp?uid=<%=uid%>&stockid=<%=stock.getStockID()%>"><%=stock.getName() %></a></td>
    					<td><%=purchasePrice%></td>
    					<td><%=owned.get(i).getQuantity()%></td>
    					<td><%=price%></td>
    					<td><%=mktVal%> </td>
    					<td><div align="center"><span style="color:<%=color%>"><%=gain %>%</span></div></td>
  					</tr>
  					
  					<%	 } 	ds.close(); %>
  				</table>
    		</div>
    		<% if (false){ %>
    		<img src="<%=user.getGraph()%>" alt="Google Chart" width="500" height="300">
    		<%} %>
    		</div>

	<!-- end #mainContent --></div>
	<br class="clearfloat" />
	<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
   <div id="footer">
    <p>Ranks will be here</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
